<?

require_once("cms/core/helper/bean/Abstract.php");
require_once("cms/core/om/BinaryFilePeer.php");
require_once("cms/download/om/DownloadPeer.php");
require_once("cms/download/om/DownloadRevisionPeer.php");

class PHP_CMS_View_Helper_Revisions extends AbstractList {

    public function revisions($form=null) {

        if($this->isInit)
            return $this;

        parent::init($form);

        $this->criteria->addJoin(DownloadRevisionPeer::DOWNLOAD_ID,
            DownloadPeer::DOWNLOAD_ID, Criteria::LEFT_JOIN);

        $this->criteria->addJoin(DownloadRevisionPeer::BINARY_FILE_ID,
            BinaryFilePeer::BINARY_FILE_ID, Criteria::LEFT_JOIN);

        $this->criteria->add(DownloadRevisionPeer::DOWNLOAD_ID, $form->getId());

        $this->criteria->setDistinct();
        
        return $this;

    }

    public function getDownload() {

        $items = $this->getItems();
        return $items[0]->getDownload();

    }


    /**
     * Define the propel peer we are going to use to list
     * page items.
     */
    public static function getPeer() {
        return new DownloadRevisionPeer();
    }


    /**
     * Return the searchable fields for this list page.
     */
    public static function getFields() {
        return array(
            DownloadPeer::DESCRIPTION,
            BinaryFilePeer::FILE_NAME,
            DownloadPeer::PUBLICATION_DATE,
            DownloadRevisionPeer::REVISION,
            DownloadRevisionPeer::INSERT_DATE,
            DownloadRevisionPeer::DESCRIPTION
        );
    }
}
?>